package com.amt.configure;

/**
 * @ClassName ThreadPoolConfig
 * @Description 线程池
 * @Author qiaomai
 * @Date 2022/11/2 16:22
 * @Version V1.0
 */

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class TreadPoolConfig {

    /** 获取当前系统的CPU 数目*/
    int cpuNums = Runtime.getRuntime().availableProcessors();
    /** 线程池核心池的大小*/
    private  int corePoolSize = 10;
    /** 线程池的最大线程数*/
    private  int maximumPoolSize = cpuNums * 5;

    /**
     * 消费队列线程
     * @return
     */
    @Bean(value = "httpApiThreadPool")
    public ExecutorService buildHttpApiThreadPool(){
        ExecutorService pool = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, 0L,
                TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(100),new ThreadFactoryBuilder().setNameFormat("PROS-%d").build());
        return pool ;
    }
}


